<?php

if ($bInit === true)
{
	
	?>
	function save_page(validateSection, publishPage, previewPage) {
		if (validateSection === null) {
			return true;
		}
		
		var oSaveParams = {
			iPageDataId : oPage.page_data_id
		};
	<?php
	
}
else 
{
	
	?>
		$('.editing_element').hide();
		$('#loading_status').html('<?php echo addslashes($aMessages['admin_pages_saving_page']); ?>').parent().show();
		
		oSaveParams.sPublishPage = publishPage;
		
		$.post('/admin/pages_ajax/save_page', oSaveParams, function(data) {
			if (data.sError) {
				alert(data.sError); // TODO: Make nice alert
				return;
			}

			
			
			if (previewPage === 'Y') {
				window.open('/preview_page/page_data_id/' + data.iPageDataId);
			}
			
			var sMessage = '<?php echo addslashes($aMessages['admin_pages_page_updated']); ?>';
			
			if (oPage.page_data_id === 0)
			{
				sMessage = '<?php echo addslashes($aMessages['admin_pages_page_created']); ?>';
			}
			
			
			oPage.page_data_id = data.iPageDataId; 
			
			$('#loading_status').html(sMessage);
			
			setTimeout(function() {
				$('#pages_options_loading').hide();
				$('.editing_element').show();
			}, 2500);
			
			oPage.page_data_id = data.iPageDataId;
			
			
		}, 'json');
		
	}
	<?php
}

?>